#include "ScubaSoldier.h"
#include "Box.h"
#include "RSManager.h"
#include "Sprite.h"
#include "Grenade.h"
#include "ShareComponents.h"
#include "Camera.h"
#include "ScubaSoldierBullet.h"

ScubaSoldier::ScubaSoldier(Box* box) : Object(box, ObjEnemy_STATIC)
{
	_sprite = RSManager::getInstance()->getSprite(SCUBA_SOLDIER);
	delay = 0;
	_up = new ScubaSoldierBullet(EFFECT_EXPLODE1);
	_left = new ScubaSoldierBullet(EFFECT_EXPLODE2);	
	_right = new ScubaSoldierBullet(EFFECT_EXPLODE2);
	_down = new ScubaSoldierBullet(EFFECT_EXPLODE2);
	_box->_size = _sprite->getRenderSize();
	_isALive = false;
}

ScubaSoldier::~ScubaSoldier(void)
{
}

void ScubaSoldier::update()
{
	if(gl_player->getCenterPos().y >= _box->_position.y + 120)
		_isALive = true;
	if(gl_player->getCenterPos().y >= _box->_position.y + 220)
		_isALive = false;
	if(_isALive)
	{
		delay += GAME_TIME;
		if(delay >= 2000)
		{
			delay = 0;
			_sprite->Next();
			if(_sprite->GetCurrentIndex() == 1)
				shoot();
		}
	}
	if(_up->isAlive())
	{
		_up->update(gl_camera->getBottom() - 100);
		prepair();
	}
	else
	{
		_left->update();
		_right->update();
		_down->update();
	}	
}

void ScubaSoldier::render()
{
	_sprite->Render(_box->_position);
	if(_up->isAlive())
		_up->render();
	else
	{
		_left->render();
		_right->render();
		_down->render();
	}
}

void ScubaSoldier::shoot()
{
	_up->process(ObjEnemy_DYNAMID, _box->_position + D3DXVECTOR2(20, 60), 12, 90);
}

void ScubaSoldier::prepair()
{
	_left->process(ObjEnemy_DYNAMID, _up->getBox()->_position, 3, 145);
	_right->process(ObjEnemy_DYNAMID, _up->getBox()->_position, 3, 35);
	_down->process(ObjEnemy_DYNAMID, _up->getBox()->_position, 3, 90);
}

Box* ScubaSoldier::getCollisionBox()
{
	return _box;
}
